﻿#pragma once

#ifndef QCEFRENDERPROCESSHANDLER_H
#define QCEFRENDERPROCESSHANDLER_H

#include "QCefHeader.h"
#include "QCefRenderClient.h"

class QCefRenderProcessHandler : public CefRenderProcessHandler
{
public:
    typedef std::unordered_map<int64, CefRefPtr<QCefRenderClient>> ClientMap;

public:
    QCefRenderProcessHandler();
    virtual ~QCefRenderProcessHandler();

protected:
    ClientMap   m_renderClients;
    bool m_lastNodeIsEditable;

public:
    //////////////////////////////////////////////////////////////////////////
    //CefRenderProcessHandler
    virtual void OnWebKitInitialized() override;

    virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser,
                                  CefRefPtr<CefDictionaryValue> extra_info) override;

    virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override;

    virtual CefRefPtr<CefLoadHandler> GetLoadHandler() override;

    virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
                                  CefRefPtr<CefFrame> frame,
                                  CefRefPtr<CefV8Context> context) override;

    virtual void OnContextReleased(CefRefPtr<CefBrowser> browser,
                                   CefRefPtr<CefFrame> frame,
                                   CefRefPtr<CefV8Context> context) override;

    virtual void OnUncaughtException(CefRefPtr<CefBrowser> browser,
                                     CefRefPtr<CefFrame> frame,
                                     CefRefPtr<CefV8Context> context,
                                     CefRefPtr<CefV8Exception> exception,
                                     CefRefPtr<CefV8StackTrace> stackTrace) override;

    virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
                                      CefRefPtr<CefFrame> frame,
                                      CefRefPtr<CefDOMNode> node) override;

    virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
                                          CefRefPtr<CefFrame> frame,
                                          CefProcessId source_process,
                                          CefRefPtr<CefProcessMessage> message) override;
};

#endif // QCEFRENDERPROCESSHANDLER_H
